import Field from 'winged/utils/wt-model-field'
import time from 'winged/utils/wt-time-utils'
export default {
		title: '文章列表',
		customFormComponent: 'wt-new-article',
		name: 'articleList',
		tableName: 'data',
		query: {
		method: 'GET',
		url:'common/articleList',
		extraParams:[],
		transfer: false,
		pagination: true,
		placeholder: '当前没有文章记录',		
		sizeParam:'page_size',
		countParam:'total',
		// resultParam: 'data'
	},
		id_field: {
		// 用于修改、删除操作的字段名
		name: 'id',
		// id字段查询结果中的tableName默认为'id'
		tableName: 'id'
	},
	new: {
		method: 'POST',
		url: 'common/article',
		transfer: false,
		extraParams: [
		]
	},
	update: {
		method: 'PUT',
		url: 'common/article',
		transfer: false,
	},
		fields: [
			{
				label:'文章类型',
				type: Field.types.select,
				display:true,
				name:'type',
				tableName:'type',
				minWidth:'50',
				noSave: false,
				noFormDisplay: true,
				options:[
					{
						label:'模板文章',
						value:'1'
					},
					{
						label:'链接文章',
						value:'2'
					}
				],
				rules: [
					{ required: true, message: '请选择文章类型', trigger: 'blur' },
				],
			},
			{
			label: '文章模板',
			type: Field.types.select,
			display: true,
			name: 'template',
			tableName: 'template',
			// customComponent: 'wt-article-template',
			minWidth:'50',
			options: [
						{
							label: '模板1',
							value: '1'
						}, {
							label: '模板2',
							value: '2'
						},
					],
			rules: [
				{ required: true, message: '请选择文章模板', trigger: 'blur' },
			],
			builder:function(data){
				
			}
		},
		{
			label: '文章类别',
			type: Field.types.select,
			display: true,
			name: 'category_id',
			tableName: 'category_id',
			customComponent: 'wt-add-select',
			multiple:false,
			remote: true,
			returnAllData: true,
			addReturnAllData: false,
			query: {
				method: 'GET',
				addMethod: 'post',
				url: 'common/article/category',
				transfer: false,
				allowAdd: true,
				param:{},
				addParam: ['name'],
				addurl: 'common/article/add_category',
				isSearch: true
			},
			builder:function(data){
				if(!data[this.tableName]){
					data[this.tableName] = '暂无类别'
				}else{
					data[this.tableName] = data.category.name
				}
			},
			rules:[
				{ required:true, message:'请选择输入文章类别'}
			]
		},
		{
			label: '页面标题',
			type: Field.types.text,
			display: true,
			name: 'title',
			tableName: 'title',
			minWidth:'50',
			// customComponent: 'title-thum-cut',
			rules: [
				{ required: true, message: '请输入页面标题', trigger: 'blur' },
			],
		},
		{
			label: '上次更新时间',
			type: Field.types.text,
			display: true,
			noSave: true,
			conditional: true,
			name: 'updated_at',
			tableName: 'updated_at',
			minWidth:'90',
			builder:function(data){
				data[this.tableName] = time.format(data[this.tableName])
			},
		},
		{
			label: '页面链接',
			type: Field.types.text,
			display: true,
			noSave: true,
			conditional: true,
			name: 'url',
			tableName: 'url',
			minWidth:'220',
		},
		{
			label: '推送',
			type: Field.types.text,
			onSave: true,
			noFormDisplay: true,
			name: 'is_push',
			tableName: 'is_push',
			customComponent: 'is-push-checkbox',
		},
		{
			label: '内容',
			type: Field.types.text,
			display: false,
			name: 'content',
			tableName: 'content',
			customComponent: 'wt-article-content-list',
			builder:function(data){
				let content;
				if(typeof(data.content) == "string"){
					content = JSON.parse(data.content);
				}
				data[this.name] = content
			},
			rules: [
			],
		},
		]
}